package com.example.controller;

import com.example.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;

@Controller
public class thymeleafController {
    @RequestMapping("/test11")
    public String test11(HttpServletRequest request){
        request.setAttribute("name","蔡徐坤");
        request.setAttribute("age","两年半");
        return "inLine";
    }
    @RequestMapping("/test10")
    public String test10(HttpServletRequest request,String gender){
        request.setAttribute("gender",gender);
        return "switch";
    }
    @RequestMapping("/test9")
    public String test9(){

        return "ifAndUnless";
    }
    @RequestMapping("/test8")
    public String test8(HttpServletRequest request){
        HashMap<String, Object> map = new HashMap<>();
        map.put("1001","zhangsan");
        map.put("1002","lisi");
        map.put("1003","wangwu");
        map.put("1004","ll");
        map.put("1005","jj");
        request.setAttribute("map",map);
        return "eachMap";
    }
    @RequestMapping("/test7")
    public String test7(HttpServletRequest request){
        ArrayList<String> list = new ArrayList<>();
        list.add("1001");
        list.add("1002");
        list.add("1003");
        list.add("1004");
        list.add("1005");
        request.setAttribute("list",list);
        return "eachList";
    }
    @RequestMapping("/test6")
    public String test6(){
        return "expression3";
    }
    @RequestMapping("/test5")
    public @ResponseBody String test5(HttpServletRequest request,String name){
        User user = new User();
        user.setName(name);
        user.setId("123456789");
        user.setCreatetime("2023-09-27");
        request.setAttribute("user",user);
        return "有参接口："+user;
    }
    @RequestMapping("/test4")
    public @ResponseBody String test4(){
        return "无参接口";
    }
    @RequestMapping("/test3")
    public String test3(HttpServletRequest request){
        User user = new User();
        user.setName("王五");
        user.setId("123456789");
        user.setCreatetime("2023-09-27");
        request.setAttribute("user",user);
        return "expression2";
    }
    @RequestMapping("/test2")
    public String test2(HttpServletRequest request){
        User user = new User();
        user.setName("王五");
        user.setId("123456789");
        user.setCreatetime("2023-09-27");
        request.setAttribute("user",user);
        return "expression1";
    }
    @RequestMapping("/test1")
    public String test1(HttpServletRequest request){
        request.setAttribute("name","我是模板thymeleaf");
        return "test1";
    }
}
